<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>黔南民族师范学院综合教育学分认定系统</title>

    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/icon.css" />
    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/default/easyui.css"/>

    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
     <style type="text/css">
		.searchbox {
		  margin: -3px;
		}
    </style> 
  	<script type="text/javascript"  th:inline="none">
  		$(function(){
  			$('#dg').datagrid({    
			    url:'/user/queryAllUser',
			    striped:true,
			    idField:'id',
			   	fitColumn:true,
			    nowrap:true, 
			    rownumber:true,
			    pagination:true, 
			    pageSize:5,
			    pageList:[5,10,15],
			    queryParams:{
			    	keyword:'%%'
			    },
			    toolbar: [{
						iconCls: 'icon-add',
						text:'添加用户',
						handler: function(){
							parent.$("#win").window({
								title:"添加用户",
								width:500,
								height:320,
								content:'<iframe src="/user/save" frameborder="0" width="100%" height="100%">'
							});
						}
					},'-',{
						iconCls: 'icon-edit',
						text:'更新用户',
						handler: function(){
							var rows = $("#dg").datagrid("getSelections");
							if(rows.length != 1){
								$.messager.show({
									title:'错误提示',
									msg:'请选中一条记录',
									timeout:5000,
									showType:'slide'
								});	
							}else{
								parent.$("#win").window({
								title:"更新用户",
								width:500,
								height:300,
								content:'<iframe src="/user/update" frameborder="0" width="100%" height="100%">'
							});
							}
						}
					},'-',{
						iconCls: 'icon-remove',
						text:'删除用户',
						handler: function(){
							var rows = $("#dg").datagrid("getSelections");
							if(rows.length != 1){
								$.messager.show({
									title:'错误提示',
									msg:'请选择一条记录',
									timeout:5000,
									showType:'slide'
								});	
							}else{
								$.messager.confirm('删除确认对话框', '是否要删除选中的记录?', function(r){
									if (r){
									    var ids = "";
									    for(var i=0;i<rows.length;i++){
									    	ids+=rows[i].id + ",";
									    }
									    ids=ids.substring(0, ids.lastIndexOf(","));
									    $.post("/user/deleteUserByIds",{ids:ids},function(result){
									    	if(result=="ok"){
									    		$("#dg").datagrid("reload");
									    		$("#dg").datagrid("uncheckAll");
									    	}else{
									    		$.messager.show({
									    			title:'删除异常',
									    			msg:'无法删除,请检查操作',
									    			timeout:2000,
									    			showType:'slide'
									    		});
									    	}
									    });
									}
								});		
							}
						}
					},'-',{
						iconCls: 'icon-ok',
						text:'设置角色',
						handler: function(){
							var rows = $("#dg").datagrid("getSelections");
							if(rows.length != 1){
								$.messager.show({
									title:'错误提示',
									msg:'请选择一条记录',
									timeout:5000,
									showType:'slide'
								});	
							}else{
								parent.$("#win").window({
								title:"设置角色",
								width:500,
								height:300,
								content:'<iframe src="/user/setroles" frameborder="0" width="100%" height="100%">'
							});
							}
						}
					},'-',{
						text:"&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' id='ss' name='truename' size='15'>"
					}
				],
			    
			    columns:[[
			   		{field:'check',checkbox:true},
			     	{field:'id',title:'编号',width:50,align:'center'},
			        {field:'username',title:'用户名',width:200,align:'center'},
			        {field:'truename',title:'真实姓名',width:200,align:'center'},
			      	{field:'status',title:'状态(在岗/不在岗)',width:200,align:'center',
			        	formatter:function(value,row,index){
			        		if(value){
			        			return "<input type='checkbox' checked='checked' disabled='disabled'>";
			        		}else{
			        			return "<input type='checkbox' disabled='true'>";
			        		}
			        	}
			        },
			        {field:'name',title:'所属机构',width:200,align:'center'}
			    ]]
			});  
			
			$('#ss').searchbox({ 
				searcher:function(value,name){ 
					$("#dg").datagrid('load',
						{
							keyword:'%'+value+'%'
						});
				}, 
				prompt:'请输入查询的名字' 
			}); 	
			
  		});
  		
  		
  	</script>
  </head>
  
  <body>
  	<table id="dg"></table>
  </body>
</html>
